package stud.mpgame.old;


import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;


public class ServerConfiguration { //Singleton

    public final String PORT = "game.server.port";
    public final String DELAY = "game.server.delay";
    public final String MAX_MESSAGE_BUFFER_SIZE = "game.server.max_message_buffer_size";
    public final String PING_DELAY = "game.server.ping_delay";

    private static ServerConfiguration instance = null;
    private Properties properties;
    private String path;

    public void initialization(String path) throws Exception {
        this.path = path;
        InputStream in = new FileInputStream(this.path);
        properties = new Properties();
        properties.load(in);
        in.close();
    }

    private ServerConfiguration() {}

    public static ServerConfiguration getInstance() {
        if(instance == null)
            instance = new ServerConfiguration();
        return instance;
    }

    public int getPort() {
        String port = properties.getProperty(PORT);
        return Integer.parseInt(port);
    }

    public int getDelay() {
        String delay = properties.getProperty(DELAY);
        return Integer.parseInt(delay);
    }

    public int getMaxMessageBufferSize() {
        String maxMessageBufferSize = properties.getProperty(MAX_MESSAGE_BUFFER_SIZE);
        return Integer.parseInt(maxMessageBufferSize);
    }

    public int getPingDelay() {
        String pingDelay = properties.getProperty(PING_DELAY);
        return Integer.parseInt(pingDelay);
    }

    public String getValue(String key) {
        return properties.getProperty(key);
    }

}